<template>
  <a-modal :open="open" width="1400px" title="病案归档" centered ok-text="保存" @ok="onOk" @cancel="onCancel">
    <div class="h-[500px]">
      <PatientInfoHeader :patient-info="selectedItem">
        <a-divider type="vertical" :style="{ height: '40px', margin: '0 16px' }" />
        <div>
          <div class="flex items-center">
            <LabelValue class="ml-4" label="住院科室" :width="140" :value="selectedItem?.ksmc" />
            <LabelValue class="ml-4" label="住院号" :width="140" :value="selectedItem?.admissionCode" />
            <!-- <LabelValue class="ml-4" label="过敏史" :width="150" :tooltip="true" :value="selectedItem?.brGms" /> -->
            <AllergyHistory class="ml-4" :width="150" :value="selectedItem.brGms" :patientInfo="selectedItem" @success="(e) => (selectedItem.brGms = e)" />
            <LabelValue class="ml-4" label="住院天数" :width="180" :value="selectedItem?.zyts" />
            <LabelValue class="ml-4" label="保险信息" :width="140" :tooltip="true" :value="selectedItem?.bxxx" />
          </div>
          <div class="flex items-center">
            <LabelValue class="ml-4" label="住院病区" :width="140" :value="selectedItem?.wardName" />
            <LabelValue class="ml-4" label="入区时间" :width="140" :value="selectedItem?.lastDeptRegTime" />
            <LabelValue class="ml-4" label="账户余额" :width="150" :value="selectedItem?.yjje && selectedItem?.yjje + '元'" />
            <LabelValue class="ml-4" label="入院诊断" :width="320" :value="selectedItem?.ryzd" />
          </div>
        </div>
      </PatientInfoHeader>
      <div class="py-16 px-32">
        <a-textarea v-model:value="formState.gdbz" :disabled="formState.bazt === 1 || formState.bazt === 2" :rows="12" placeholder="请输入归档备注" />
      </div>
    </div>
  </a-modal>
</template>
<script setup>
import { ref, watch } from 'vue'
import { message } from 'ant-design-vue'
import { post } from '@/utils/request'
import PatientInfoHeader from '@/components/business/PatientInfoHeader'

const emit = defineEmits(['update:open', 'success'])
const props = defineProps({
  open: Boolean,
  rowData: {
    type: Object,
    default: () => ({})
  }
})

const formState = ref({})
const selectedItem = ref({})

// 获取用户信息
const getRecordInfo = async () => {
  const { code, data, msg } = await post('/inp/zydj/getInpRecordList', { inpLshList: [formState.value?.inplsh] })
  if (code !== 0) return message.error(msg)
  selectedItem.value = data?.[0]
}

const onOk = async () => {
  const { code, msg } = await post('/med/MedicalRecord/doFilingOfMedicalRecords', {
    inplsh: formState.value?.inplsh,
    status: 2,
    storeLabel: formState.value?.gdbz
  })
  if (code !== 0) return message.error(msg)
  message.success(msg)
  onCancel()
  emit('success')
}

const onCancel = () => {
  emit('update:open', false)
}

watch(
  () => props.open,
  (val) => {
    if (val) {
      formState.value = { ...props.rowData }
      getRecordInfo()
    }
  }
)
</script>

<style lang="less" scoped></style>
